function handles = makeMapDataArray(handles)
% makeMapDataArray
%
% gs april 2005

planePattern =      1;      % map pattern
planeEC =           2;      % EC
planeED =           3;      % ED
planeIC =           4;      % IC
planeGenMinAmp =    5;      % genMinAmp
planeAPnumber =     6;      % AP number
planeAPdelay =      7;      % AP delay
planeAP =           8;      % AP occurrence
planeGenMean =      9;      % genMean
planeGenOnset =     10;     % genOnset (min)
planeGenMax =       11;     % genMax
planeGenMaxOnset =  12;     % genMaxOnset
planeAmpHistBase =  13;     % amplitude histogram baseline map
planeAmpHistSyn  =  14;     % amplitude histogram synaptic map
planeGenMeanAmp4th= 15;     %
planeGenMinAmp4th = 16;     %
planeGenMaxAmp4th = 17;     %

% map pattern
handles.data.map.mapActive.mapDataArray = handles.data.map.mapActive.mapPattern;

% EC
try
    a = find(abs(handles.data.map.mapActive.ecAmp)>0); 
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeEC) = handles.data.map.mapActive.ecAmp(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeEC) = handles.data.map.mapActive.mapPattern + NaN;
end

% ED
try
    a = find(abs(handles.data.map.mapActive.edAmp)>0); 
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeED) = handles.data.map.mapActive.edAmp(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeEC) = handles.data.map.mapActive.mapPattern + NaN;
end

% IC
try
    a = find(abs(handles.data.map.mapActive.icAmp)>0); 
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeIC) = handles.data.map.mapActive.icAmp(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeEC) = handles.data.map.mapActive.mapPattern + NaN;
end

% genMinAmp
try
    a = find(handles.data.map.mapActive.mapPattern); 
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeGenMinAmp) = handles.data.map.mapActive.genMinAmp(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeEC) = handles.data.map.mapActive.mapPattern + NaN;
end

% AP number
handles.data.map.mapActive.mapDataArray(:,:,planeAPnumber) = zeros;
try
    a = find(handles.data.map.mapActive.apNumber>0); %
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeAPnumber) = handles.data.map.mapActive.apNumber(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeAPnumber) = handles.data.map.mapActive.mapDataArray(:,:,1) + NaN; % klugey
end

% AP delay
try
    
    a = find(handles.data.map.mapActive.apDelay>0); %
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeAPdelay) = handles.data.map.mapActive.apDelay(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeAPdelay) = handles.data.map.mapActive.mapDataArray(:,:,1) + NaN; % klugey
end

% AP occurrence (i.e., 0 if no AP, 1 if any AP)
try
    binaryAPmap = handles.data.map.mapActive.mapDataArray(:,:,planeAPnumber);
    binaryAPmap(find(binaryAPmap>0)) = 1;
    handles.data.map.mapActive.mapDataArray(:,:,planeAP) = binaryAPmap;
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeAP) = handles.data.map.mapActive.mapDataArray(:,:,1) + NaN; % klugey
end

% genMean
try
    a = find(handles.data.map.mapActive.mapPattern); 
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeGenMean) = handles.data.map.mapActive.genMeanAmp(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeEC) = handles.data.map.mapActive.mapPattern + NaN;
end

% genOnset -- note that this is for the MIN
try
    a = find(handles.data.map.mapActive.mapPattern); 
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeGenOnset) = handles.data.map.mapActive.genLatOfMinOnset(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeEC) = handles.data.map.mapActive.mapPattern + NaN;
end

% genMax
try
    a = find(handles.data.map.mapActive.mapPattern); 
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeGenMax) = handles.data.map.mapActive.genMaxAmp(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeEC) = handles.data.map.mapActive.mapPattern + NaN;
end

% genMaxOnset
try
    a = find(handles.data.map.mapActive.mapPattern); 
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeGenMaxOnset) = handles.data.map.mapActive.genLatOfMaxOnset(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeEC) = handles.data.map.mapActive.mapPattern + NaN;
end

% amplitude histogram baseline map
try
    a = find(handles.data.map.mapActive.mapPattern); 
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeAmpHistBase) = handles.data.map.mapActive.ampHistoBaselineData(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeEC) = handles.data.map.mapActive.mapPattern + NaN;
end

% amplitude histogram synaptic map
try
    a = find(handles.data.map.mapActive.mapPattern); 
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeAmpHistSyn) = handles.data.map.mapActive.ampHistoSynapticData(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeEC) = handles.data.map.mapActive.mapPattern + NaN;
end

% 'fourth window' stuff added dec 2006 gs
% planeGenMeanAmp4th
try
    a = find(handles.data.map.mapActive.mapPattern); 
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeGenMeanAmp4th) = handles.data.map.mapActive.genMeanAmp4th(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeEC) = handles.data.map.mapActive.mapPattern + NaN;
end

% planeGenMinAmp4th
try
    a = find(handles.data.map.mapActive.mapPattern); 
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeGenMinAmp4th) = handles.data.map.mapActive.genMinAmp4th(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeEC) = handles.data.map.mapActive.mapPattern + NaN;
end

% planeGenMaxAmp4th
try
    a = find(handles.data.map.mapActive.mapPattern); 
    for n = 1:length(a)
        [I,J] = find(handles.data.map.mapActive.mapPattern == a(n));
        handles.data.map.mapActive.mapDataArray(I,J,planeGenMaxAmp4th) = handles.data.map.mapActive.genMaxAmp4th(a(n));
    end
catch
    handles.data.map.mapActive.mapDataArray(:,:,planeEC) = handles.data.map.mapActive.mapPattern + NaN;
end
